<?php
/*
 * Effettuo una FQL QUERY (multiquery)
 */
$facebook = MyFacebook::getInstance();
$uid = $facebook->getUser();
echo "<h1>Il mio uid: $uid</h1>";
$queryForApplication = "SELECT canvas_name, display_name FROM application WHERE app_id  IN
              (SELECT application_id FROM developer WHERE developer_id =".$uid.")";
$queryForPage = "SELECT page_id, name FROM page WHERE page_id  IN
              (SELECT page_id FROM page_admin WHERE uid =".$uid.")";

$arrayCall = array(
"method" => "fql.multiquery",
"queries" => array("applicazioni" => $queryForApplication,"pagine" => $queryForPage)
);
try {
  $query = $facebook->api($arrayCall);
  if ($query) {
    $listApp = $query[0]["fql_result_set"];
    echo "<p>Le Applicazioni di cui sono sviluppatore:</p>";
    echo "<ul>";
    foreach($listApp as $app) {
      echo "<li>".$app["display_name"]."</li>";
    }
    echo "</ul>";
    $listPage = $query[1]["fql_result_set"];
    echo "<p>Le Pagine che amministro:</p>";
    echo "<ul>";
    foreach($listPage as $page) {
      echo "<li><a href=\"index.php?action=detailpage&id=".$page["page_id"]."\">".$page["name"]."</a></li>";
    }
    echo "</ul>";
    
    echo "<code>";
    echo "<pre>".print_r($query, true)."</pre>";
    echo "</code>";
  } else {
    echo "<p>Query non eseguita</p>";
  }
} catch (FacebookApiException $e) {
  echo "ERRORE: ".$e;
}
?>
<p>Documentazione Tabelle utilizzate:
<ul>
<li><a target="_blank" href="http://developers.facebook.com/docs/reference/fql/application">Tabella Applicazioni</a></li>
<li><a target="_blank" href="http://developers.facebook.com/docs/reference/fql/developer">Relazione Applicazioni/Utenti (Sviluppatori)</a></li>
<li><a target="_blank" href="http://developers.facebook.com/docs/reference/fql/page">Tabella Pagine</a></li>
<li><a target="_blank" href="http://developers.facebook.com/docs/reference/fql/page_admin">Relazione Pagine/Utente Amministratore</a></li>
</ul>
</p>